package com.offcn.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.offcn.mapper.PermissionMapper;
import com.offcn.mapper.RoleMapper;
import com.offcn.mapper.UserMapper;
import com.offcn.pojo.Permission;
import com.offcn.pojo.Role;
import com.offcn.pojo.User;
import com.offcn.service.UserService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @program: offcnpe_parent
 * @description:
 * @author: xin yi
 * @create: 2021-07-23 20:54
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private PermissionMapper permissionMapper;


    @Override
    public User getUserByUsername(String username) {
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("username",username);
        User user = userMapper.selectOne(userQueryWrapper);
        return user;
    }

    @Override
    public List<Role> getRolesByUserId(Integer uid) {
        return roleMapper.getRoleByUid(uid);
    }

    @Override
    public List<Permission> getPermisionsByUserId(Integer uid) {
        return permissionMapper.getPermissionByUid(uid);
    }
}
